// ignore_for_file: avoid_print

import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hibrid_flutter/finance/finance_state_page.dart';
import 'package:package_info/package_info.dart';
import 'package:path_provider/path_provider.dart';
import 'package:player/player.dart';
import 'my_route.dart';
import 'finance/finance_page.dart';

void main() {
  runApp(const MyApp());
  init();
}

@pragma('vm:entry-point')
void finance() {
  runApp(const FinanceApp());
}

String externalStorage =
    '/storage/emulated/0/Android/data/com.wenhua.yuan.hibrid_flutter.host/files';

void init() {
  getExternalStorageDirectory()
      .then((value) => externalStorage = value?.path ?? externalStorage);
  Player.setCachePath(externalStorage);
  print('video-path - $externalStorage');

  PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
    // 获取应用包名
    String appName = packageInfo.appName;
    String packageName = packageInfo.packageName;
    print('video-app-package - $appName|$packageName');
  });

  print('route - init=>${window.defaultRouteName}');
//  myRoute.push(name: MyRoute.minePage);
  myRoute.push(name: window.defaultRouteName);
//  Get.to(MinePage());// 使用Get替代路由功能，这里不行
}

/// Route创建出一个全局的，放到顶层使用
MyRoute myRoute = MyRoute();

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    /// getx:该造步骤1:包装GetMaterialApp
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      // 移除debug模式下右上角标识
      title: '第一个flutter入口',
      color: Colors.transparent,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Router(
        routerDelegate: myRoute,
        backButtonDispatcher: RootBackButtonDispatcher(),
      ),
    );
  }
}

class FinanceApp extends StatelessWidget {
  const FinanceApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false, // 隐藏屏幕 'DEBUG'角标
      title: '基金详情入口',
      color: Colors.transparent,
      theme: ThemeData(
        primarySwatch: Colors.red,
      ),
      home: const FinanceStatePage(),
    );
  }
}
